package com.redxun.service.impl;

import cn.hutool.core.util.IdUtil;
import com.redxun.core.common.utils.ContextUtil;
import com.redxun.model.request.ClaimRequest;
import com.redxun.model.request.IndicatorsRequest;
import com.redxun.model.response.BaseResponse;
import com.redxun.model.response.ClaimPoJo;
import com.redxun.model.response.IndicatorsPoJo;
import com.redxun.model.vo.*;
import com.redxun.service.IndicatorsReview;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
@Slf4j
public class IndicatorsReviewImpl extends BaseService implements IndicatorsReview {
    @Override
    public BaseResponse<IndicatorsPoJo> batchReview(IndicatorsRequest request) {
        String type = request.getType();
        List<String> ids = request.getIds();
        IndicatorsPoJo indicatorsPoJo = new IndicatorsPoJo();
        List<String> failMessage = new ArrayList<>();
        List<String> successMessage = new ArrayList<>();
        if("资金待审".equals(type)){ // 修改审核状态
            indicatorsReviewDao.updateIdViod(ids);
            // 添加返回结果
            indicatorsPoJo.setSuccessCount(ids.size());
            for (String id : ids) {
                String zjBh = indicatorsReviewDao.selectZjds(id);
                successMessage.add("资金待审编号["+zjBh+"]审核成功！");
            }
            indicatorsPoJo.setSuccessMessage(successMessage);
            indicatorsPoJo.setFailCount(0);
            indicatorsPoJo.setFailMessage(failMessage);
            return BaseResponse.success(indicatorsPoJo);
        }else if("分配待审".equals(type)){
        // 1.根据ids查询列表进行正序排列
        List<ZbfpVo> zbfpVoList = indicatorsReviewDao.selectBatchIds(ids);
        // 2.查询分配明细并且按照ZJHF字段进行分组合并金额作为当前需要的金额
            for (ZbfpVo zbfpVo : zbfpVoList) {
                // 1.查询分配明细
                List<ZbfpmxVo> zbfpmxVoList = indicatorsReviewDao.selectZbfpmxByZbfpId(zbfpVo.getId());
                // 2.按照ZJHF字段进行分组合并金额作为当前需要的金额<分类，金额>
                Map<String, BigDecimal> needResult = zbfpmxVoList.stream()
                        .collect(Collectors.groupingBy(
                                ZbfpmxVo::getZjhf,
                                Collectors.reducing(
                                        BigDecimal.ZERO,
                                        ZbfpmxVo::getFpje,
                                        BigDecimal::add
                                )
                        ));
                // 3.查询指标的分配金额<分类，金额>
                ZbdjVo zbdjVo = indicatorsReviewDao.selectZbdjByZbpfBUTTONEDITCTLDCNAME(zbfpVo.getButtoneditCtldcName());
                List<ZjhfVo> zjhfVos = indicatorsReviewDao.selectZjhfByZbdjId(zbdjVo.getId());
                Map<String, BigDecimal> haveResult = zjhfVos.stream()
                        .collect(Collectors.groupingBy(
                                ZjhfVo::getZjhf,
                                Collectors.reducing(
                                        BigDecimal.ZERO,
                                        ZjhfVo::getZbje,
                                        BigDecimal::add
                                )
                        ));
                // 4.查询指标已使用的金额<分类，金额>
                List<ZbfpVo> usedList = indicatorsReviewDao.selectUsedZbfpList(zbfpVo.getButtoneditCtldcName());
                Map<String, BigDecimal> usedResult = Collections.emptyMap();
                if(!usedList.isEmpty()){
                    List<String> useIds = usedList.stream()
                            .map(ZbfpVo::getId)
                            .collect(Collectors.toList());
                    List<ZbfpmxVo> useZbfpmxVoList = indicatorsReviewDao.selectBatchZbfpmxByZbfpIds(useIds);
                    // 2.按照ZJHF字段进行分组合并金额作为当前需要的金额<分类，金额>
                    usedResult = useZbfpmxVoList.stream()
                            .collect(Collectors.groupingBy(
                                    ZbfpmxVo::getZjhf,
                                    Collectors.reducing(
                                            BigDecimal.ZERO,
                                            ZbfpmxVo::getHfje,
                                            BigDecimal::add
                                    )
                            ));
                }
                boolean isFail = false;
                boolean isQl = false;
                BigDecimal xfp = BigDecimal.ZERO;
                BigDecimal wfp = BigDecimal.ZERO;
                for (Map.Entry<String, BigDecimal> needEntry : needResult.entrySet()) {
                    String fplx = needEntry.getKey();
                    BigDecimal needAmount = needEntry.getValue();

                    BigDecimal haveAmount = haveResult.getOrDefault(fplx, BigDecimal.ZERO);
                    BigDecimal usedAmount = usedResult.getOrDefault(fplx, BigDecimal.ZERO);
                    BigDecimal availableAmount = haveAmount.subtract(usedAmount);

                    if (availableAmount.compareTo(needAmount) < 0) {
                        isFail = true;
                        break;
                    }else if(availableAmount.compareTo(needAmount) != 0){
                        isQl = true;
                    }
                    xfp  = xfp.add(needAmount);
                    wfp = wfp.add(haveAmount.subtract(usedAmount.add(needAmount)));
                }
                if(isFail){ // 失败
                    indicatorsPoJo.setFailCount(indicatorsPoJo.getFailCount() + 1);
                    failMessage.add("资金分配编号["+zbfpVo.getInputXmbri() + "]分配资金不足，不允许通过！");
                }else {// 审核通过
                    String id = zbfpVo.getId();
                    String buttoneditCtldc = zbfpVo.getButtoneditCtldc();
                    // 更新分配主表状态
                    indicatorsReviewDao.updateSELECTD6U8E(zbfpVo.getId());
                    if(isQl){ // 部分分配
                        indicatorsReviewDao.updateBf(buttoneditCtldc,xfp,wfp);
                    }else{
                        indicatorsReviewDao.updateAll(buttoneditCtldc,xfp,wfp);
                    }

                    // 中间表插入数据
                    indicatorsReviewDao.insetFpzjb(id);
                    indicatorsPoJo.setSuccessCount(indicatorsPoJo.getSuccessCount() + 1);
                    successMessage.add("资金分配编号["+zbfpVo.getInputXmbri() + "]已成功通过审核！");
                    indicatorsPoJo.setSuccessMessage(successMessage);
                }
            }
            indicatorsPoJo.setFailMessage(failMessage);
            return BaseResponse.success(indicatorsPoJo);
        }else if("到账待审".equals(type)){
            for (String id : ids) {
                BfdjVo vo = indicatorsReviewDao.getBfdjById(id);
                String zjfpId = vo.getInput7eaus();
                String zbId = vo.getButtonedit918xg();
                // 查询拨付合计金额
                String bfhj = indicatorsReviewDao.getBfhj(zbId,id);
                BigDecimal ybf = new BigDecimal(bfhj);
                BigDecimal zbje = vo.getNumberPts01();
                BigDecimal bcbf = vo.getNumberKekgi();
                BigDecimal bckbf = zbje.subtract(ybf);
                BigDecimal xbf = bcbf.add(ybf);
                BigDecimal wbf =zbje.subtract(xbf);
                if(bckbf.compareTo(bcbf) < 0){
                    indicatorsPoJo.setFailCount(indicatorsPoJo.getFailCount() + 1);
                    failMessage.add("到账编号["+vo.getInputGjlmd()+"]本次拨付金额"+bcbf+"超过剩余未到账金额"+bckbf+",不允许通过！");
                    indicatorsPoJo.setFailMessage(failMessage);
                }else{
                    // 更新拨付登记表
                    indicatorsReviewDao.updateBfdj(id);
                    if(zbje.compareTo(xbf)>0){ // 部分到账
                        indicatorsReviewDao.updateBfdz(xbf,wbf,zbId);
                    }
                    if(zbje.compareTo(xbf)==0){ // 全部到账
                        indicatorsReviewDao.updateAlldz(xbf,wbf,zbId);
                    }
                    // 修改中间表对应拨付、未拨付金额
                    indicatorsReviewDao.updateFpzjb(zjfpId,xbf,bcbf);
                    indicatorsPoJo.setSuccessCount(indicatorsPoJo.getSuccessCount() + 1);
                    successMessage.add("到账编号["+vo.getInputGjlmd()+"]已成功通过审核！");
                    indicatorsPoJo.setSuccessMessage(successMessage);
                }
            }
            return BaseResponse.success(indicatorsPoJo);
        }else if("调拨待审".equals(type)){
            for (String id : ids) {
                DbdjVo vo = indicatorsReviewDao.selectDbdj(id);
                String dcid = vo.getInputS1tzs();
                String drid = vo.getInputGwqdf();
                BigDecimal kdc = BigDecimal.valueOf(indicatorsReviewDao.selectFpzjb(dcid));
                BigDecimal bcdr = vo.getNumberKybur();
                if(kdc.compareTo(bcdr) >= 0){
                    //修改本表数据状态
                    indicatorsReviewDao.updaDbdj(kdc,id);
                    //查询调出指标调出合计
                    BigDecimal dchj = BigDecimal.valueOf(indicatorsReviewDao.selectDbdjByInputS1tzs(dcid));
                    // 修改中间表调出指标被调用金额金额和未使用金额
                    indicatorsReviewDao.updateFpzjbBydbDc(dchj,dcid);
                    //查询调入指标调入合计
                    BigDecimal drhj = BigDecimal.valueOf(indicatorsReviewDao.selectDrHj(drid));
                    //修改中间表调入指标调拨金额和未使用金额
                    indicatorsReviewDao.updateFpzjbBydbDr(drhj,drid);
                    indicatorsPoJo.setSuccessCount(indicatorsPoJo.getSuccessCount() + 1);
                    successMessage.add("调拨编号["+vo.getInputVh2qs()+"]已成功通过审核！");
                    indicatorsPoJo.setSuccessMessage(successMessage);
                }else{
                    indicatorsPoJo.setFailCount(indicatorsPoJo.getFailCount() + 1);
                    failMessage.add("调拨编号["+vo.getInputVh2qs()+"]本次调入金额"+bcdr+"超过调出指标的剩余未使用金额"+kdc+",不允许通过！");
                    indicatorsPoJo.setFailMessage(failMessage);
                }
            }
            return BaseResponse.success(indicatorsPoJo);
        }else if("归还待审".equals(type)){
            for (String id : ids) {
                GhdjVo vo = indicatorsReviewDao.selectGhdj(id);
                String ghid = vo.getInputI6rvg();
                String dcid = vo.getInputW9c84();
                //查询归还指标未使用金额，判断当前归还金额是否超过未使用
                BigDecimal kgh = BigDecimal.valueOf(indicatorsReviewDao.selectFpzjb(ghid));
                BigDecimal bcgh = vo.getNumberI5eq9();
                if(kgh.compareTo(bcgh) >= 0){
                    //修改本表数据状态
                    indicatorsReviewDao.updaGhdj(kgh,id);
                    //查询调出指标被归还合计
                    BigDecimal bghhj = BigDecimal.valueOf(indicatorsReviewDao.selectGhdjByIputw9c84(dcid));
                    //修改中间表调出指标收回金额和未使用金额(拨付金额-调出金额+收回金额+调入金额-归还金额+结转金额-使用金额)
                    indicatorsReviewDao.updateFpzjbByGhDc(bghhj,dcid);
                    //查询归还指标归还合计
                    BigDecimal ghhj = BigDecimal.valueOf(indicatorsReviewDao.selectGhHj(ghid));
                    //修改中间表归还指标归还金额和未使用金额
                    indicatorsReviewDao.updateFpzjbByGhRk(ghhj,ghid);
                    indicatorsPoJo.setSuccessCount(indicatorsPoJo.getSuccessCount() + 1);
                    successMessage.add("归还编号["+vo.getInput3nzhr()+"]已成功通过审核！");
                    indicatorsPoJo.setSuccessMessage(successMessage);
                }else{
                    indicatorsPoJo.setFailCount(indicatorsPoJo.getFailCount() + 1);
                    failMessage.add("归还编号["+vo.getInput3nzhr()+"]本次归还金额"+bcgh+"超过调出指标的剩余未使用金额"+kgh+",不允许通过！");
                    indicatorsPoJo.setFailMessage(failMessage);
                }

            }
            return  BaseResponse.success(indicatorsPoJo);
        }else if("结项待审".equals(type)){
            for (String id : ids) {
                String zjbh = indicatorsReviewDao.getZjjzBh(id);
                List<JzmxVo> jzmxVos = indicatorsReviewDao.selectJzmx(id);
                boolean isFail = false;
                for (JzmxVo jzmxVo : jzmxVos) {
                    String zjbid = jzmxVo.getZjbid();
                    BigDecimal jzje = jzmxVo.getJzje();
                    BigDecimal kjzje = BigDecimal.valueOf(indicatorsReviewDao.selectKjzje(zjbid));
                    if (kjzje.compareTo(jzje) != 0){
                        isFail = true;
                        break;
                    }
                }
                if (!isFail){ // 正确数据
                    // 更新数据状态为生效
                    indicatorsReviewDao.updateJzmx(id);
                    // 更新中间表未到账金额和结转金额
                    for (JzmxVo jzmxVo : jzmxVos) {
                        String zjbid = jzmxVo.getZjbid();
                        BigDecimal jzje = jzmxVo.getJzje();
                        String glxm = jzmxVo.getGlxm();
                        indicatorsReviewDao.updateZjbByJzmx(zjbid,jzje);
                        Long zjmxId = IdUtil.getSnowflakeNextId();
                        indicatorsReviewDao.insetSubTable(zjmxId,glxm,"结转资金",jzje);
                    }
                    indicatorsPoJo.setSuccessCount(indicatorsPoJo.getSuccessCount() + 1);
                    successMessage.add("结项编号["+zjbh+"]已成功通过审核！");
                    indicatorsPoJo.setSuccessMessage(successMessage);
                }else{
                    indicatorsPoJo.setFailCount(indicatorsPoJo.getFailCount() + 1);
                    failMessage.add("结项编号["+zjbh+"]当前结项金额超过可结项金额，不可结项！");
                    indicatorsPoJo.setFailMessage(failMessage);
                }
            }
            return  BaseResponse.success(indicatorsPoJo);
        }else if("回收待审".equals(type)){
            for (String id : ids) {
                String hsBh = indicatorsReviewDao.getHsBh(id);
                List<HsmxVo> hsmxVos = indicatorsReviewDao.selectHsmx(id);
                boolean isFail = false;
                for (HsmxVo hsmxVo : hsmxVos) {
                    String zjbid = hsmxVo.getZjbid();
                    BigDecimal bchsje = hsmxVo.getHsje();
                    BigDecimal khsje = BigDecimal.valueOf(indicatorsReviewDao.selectKhsje(zjbid));
                    if (khsje.compareTo(bchsje) < 0){
                        isFail = true;
                        break;
                    }
                }
                if (!isFail){
                    indicatorsReviewDao.updateHsStatus(id);
                    for (HsmxVo hsmxVo : hsmxVos) {
                        String zjbid = hsmxVo.getZjbid();
                        BigDecimal bchsje = hsmxVo.getHsje();
                        //更新中间表未到账金额和回收金额
                        indicatorsReviewDao.updateFpzjbByHs(zjbid,bchsje);
                    }
                    indicatorsPoJo.setSuccessCount(indicatorsPoJo.getSuccessCount() + 1);
                    successMessage.add("回收编号["+hsBh+"]已成功通过审核！");
                    indicatorsPoJo.setSuccessMessage(successMessage);
                }else{
                    indicatorsPoJo.setFailCount(indicatorsPoJo.getFailCount() + 1);
                    failMessage.add("回收编号["+hsBh+"]当前回收金额超过可回收金额，不可回收！");
                    indicatorsPoJo.setFailMessage(failMessage);
                }
            }
            return  BaseResponse.success(indicatorsPoJo);
        }else if("项目待审".equals(type)){

        }else{
            return BaseResponse.fail("审核类型不存在");
        }
        return null;
    }

    @Override
    public BaseResponse<ClaimPoJo> claim(ClaimRequest request) {
        String type = request.getType();
        List<String> ids = request.getIds();
        String middleTableId = request.getMiddleTableId();
        ClaimPoJo claimPoJo = new ClaimPoJo();
        List<String> successMessage = new ArrayList<>();
        List<String> failMessage = new ArrayList<>();
        List<String> successPayIds = new ArrayList<>();
        FpzjbVo fpzjbVo = indicatorsReviewDao.getFpzjb(middleTableId);
        if("一体化认领".equals(type)){
            String result = String.join(",", ids);
            // 未使用金额
            BigDecimal wsyje = fpzjbVo.getNumberRmv6p();
            // 本次支付金额合计
            BigDecimal bczfjehj = BigDecimal.valueOf(indicatorsReviewDao.selectYthBcHjJe(ids));
            if (wsyje.compareTo(bczfjehj) >= 0){
                // 更新中间表的使用金额和未使用金额
                indicatorsReviewDao.updateZjbByYthSyjeAndWsyje(middleTableId,bczfjehj);
                claimPoJo.setSuccessCount(ids.size());
                for (String id : ids) {
                    successMessage.add("一体化认领成功，已更新支付id为["+id+"]");
                }
                claimPoJo.setSuccessMessage(successMessage);
                claimPoJo.setSuccessPayIds(ids);
                claimPoJo.setFailCount(0);
            }else{
                claimPoJo.setFailCount(ids.size());
                for (String id : ids) {
                    failMessage.add("一体化认领失败，更新支付失败id为["+id+"]，本次支付金额合计超过未使用金额，不可认领！");
                }
                claimPoJo.setFailMessage(failMessage);
                claimPoJo.setSuccessCount(0);
                claimPoJo.setSuccessPayIds(successPayIds);
            }
            return BaseResponse.success(claimPoJo);
        }else if ("其他认领".equals(type)){
            String result = String.join(",", ids);
            // 未使用金额
            BigDecimal wsyje = fpzjbVo.getNumberRmv6p();
            // 本次支付金额合计
            BigDecimal bczfjehj = BigDecimal.valueOf(indicatorsReviewDao.selectQtBcHjJe(ids));
            if (wsyje.compareTo(bczfjehj) >= 0){
                // 更新中间表的使用金额和未使用金额
                indicatorsReviewDao.updateZjbByQtSyjeAndWsyje(middleTableId,bczfjehj);
                claimPoJo.setSuccessCount(ids.size());
                for (String id : ids) {
                    successMessage.add("其他认领成功，已更新支付id为["+id+"]");
                }
                claimPoJo.setSuccessMessage(successMessage);
                claimPoJo.setSuccessPayIds(ids);
                claimPoJo.setFailCount(0);
            }else{
                claimPoJo.setFailCount(ids.size());
                for (String id : ids) {
                    failMessage.add("其他认领失败，更新支付失败id为["+id+"]，本次支付金额合计超过未使用金额，不可认领！");
                }
                claimPoJo.setFailMessage(failMessage);
                claimPoJo.setSuccessCount(0);
                claimPoJo.setSuccessPayIds(successPayIds);
            }
            return BaseResponse.success(claimPoJo);
        }else if ("认领转代管".equals(type)){

            String result = String.join(",", ids);
            // 未使用金额
            BigDecimal wsyje = fpzjbVo.getNumberRmv6p();
            // 本次支付金额合计
            BigDecimal bczfjehj = BigDecimal.valueOf(indicatorsReviewDao.selectRlzdgBcHjJe(ids));
            if (wsyje.compareTo(bczfjehj) >= 0){
                // 更新中间表的使用金额和未使用金额
                indicatorsReviewDao.updateZjbByRlzdgSyjeAndWsyje(middleTableId,bczfjehj);
                // 四、写入数据到资金登记表和资金登记明细表
                    //1、获取中间表中的资金编号
                String zjbzjbh = indicatorsReviewDao.getZjbzjbh(middleTableId);
                //2、获取需要插入的数据
                Long zbId = IdUtil.getSnowflakeNextId();
                // 生成日期部分
                String dateStr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
                String prefix = "ZDGZB" + dateStr;
                // 查询当天最大的编号
                String maxNo = indicatorsReviewDao.selectMaxInputYula3ByDate(prefix);
                String zjbh = getString(maxNo, prefix);
                // 数据状态
                String sjzt = "生效";
                String djr = ContextUtil.getCurrentUser().getUserId();
                String djrname = ContextUtil.getCurrentUser().getFullName();
                String djrDeptId = ContextUtil.getCurrentUser().getDeptId();
                // 登记日期
                String djrq = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd 00:00:00"));
                // 资金来源
                String zjly = "代管";
                // 资金年份  资金文号   资金文件名称
                ZbdjVo zbdjVo = indicatorsReviewDao.selectZbdjByZjbBh(zjbzjbh);
                BigDecimal zjnf = zbdjVo.getSelectKp7ea();
                String zjwh = zbdjVo.getInputTmcyc();
                String zjwjmc = zbdjVo.getInputEh00o();
                // 3.插入zbgl_zbdjb
                indicatorsReviewDao.insertZbdj(zbId,zjbh,sjzt,djr,djrname,djrDeptId,djrq,zjnf,zjwh,zjly,zjwjmc,bczfjehj,bczfjehj,bczfjehj);
                // 4.获取中间表的资金划分
                String zjhf = indicatorsReviewDao.getZjhf(middleTableId);
                // 5、插入subTable_isdk9表
                Long zbmxId = IdUtil.getSnowflakeNextId();
                indicatorsReviewDao.insertSubTableIsdk9(zbmxId,zbId,zjhf,bczfjehj);
                // 五、插入数据到分配表和分配明细表
                //1、获取需要插入的数据
                prefix = "ZDGFP" + dateStr;
                maxNo = indicatorsReviewDao.selectFpbMaxInputYula3ByDate(prefix);
                String djbh = getString(maxNo, prefix);
                //2、插入数据到分配表zbgl_zbfpb
                Long fpId = IdUtil.getSnowflakeNextId();
                BigDecimal wfpje = BigDecimal.ZERO;
                indicatorsReviewDao.insertFpb(fpId,djbh,sjzt,djr,djrname,djrDeptId,djrq,zbId,zjbh,zjnf,zjwh,zjly,zjwjmc,bczfjehj,bczfjehj,wfpje,bczfjehj);
                //3、插入数据到分配明细表
                String deptId = fpzjbVo.getGroupGetar();
                String deptName = fpzjbVo.getGroupGetarName();
                Long fpmxId = IdUtil.getSnowflakeNextId();
                indicatorsReviewDao.insertFpbDetail(fpmxId,fpId,zjhf,bczfjehj,wfpje,deptId,deptName,bczfjehj);
                // 六、插入数据到中间表zbgl_fpzjb
                Long fpzjbId = IdUtil.getSnowflakeNextId();
                indicatorsReviewDao.insertFpzjb(fpzjbId,zbId,zjbh,zjnf,zjwh,zjly,zjwjmc,bczfjehj,zjhf,bczfjehj,deptId,deptName,bczfjehj,bczfjehj,bczfjehj,fpId,djrDeptId);
                // 七、插入数据到到账表zbgl_bfdjb
                prefix = "ZDGBF" + dateStr;
                maxNo = indicatorsReviewDao.selectDzbMaxInputYula3ByDate(prefix);
                String dzbh = getString(maxNo, prefix);
                Long dzId = IdUtil.getSnowflakeNextId();
                indicatorsReviewDao.insertDzb(dzId,dzbh,sjzt,djr,djrname,djrDeptId,djrq,zbId,zjbh,zjnf,zjwh,zjly,zjwjmc,bczfjehj,zjhf,bczfjehj,deptId,deptName,bczfjehj,bczfjehj,bczfjehj,fpzjbId);
                claimPoJo.setSuccessCount(ids.size());
                for (String id : ids) {
                    successMessage.add("认领转代管成功，已更新支付id为["+id+"]");
                }
                claimPoJo.setSuccessMessage(successMessage);
                claimPoJo.setSuccessPayIds(ids);
                claimPoJo.setFailCount(0);
            }else{
                claimPoJo.setFailCount(ids.size());
                for (String id : ids) {
                    failMessage.add("认领转代管失败，认领转代管失败id为["+id+"]，本次支付金额合计超过未使用金额，不可认领转代管！");
                }
                claimPoJo.setFailMessage(failMessage);
                claimPoJo.setSuccessCount(0);
                claimPoJo.setSuccessPayIds(successPayIds);
            }
            return BaseResponse.success(claimPoJo);
        }else{
            return BaseResponse.fail("认领不存在");
        }
    }

    @NotNull
    private static String getString(String maxNo, String prefix) {
        int nextSeq = 1;
        if (maxNo != null) {
            String seqStr = maxNo.substring(prefix.length());
            nextSeq = Integer.parseInt(seqStr) + 1;
        }
        String seqStr = String.format("%03d", nextSeq);
        return prefix + seqStr;
    }
}
